var $ = Dom7;
Tida.ready({
    module : ["device", "media", "server", "social", "widget", "sensor", "share","buy","draw","im","calendar","prize"],
    // debug : 1,
    // combo: 0,
    interactId : Tida.getParam("interactId")||"c27335b4-c510-4183-a8e6-19ad57a1dc8a"//"c69bb4a4-dc94-4076-9aec-1baeb47b70b4"//"8ecc923e-0d5c-4f65-ae55-49dc22d2d8f1"//"462b2fd6-84fb-4d55-b451-bde8e19fc475"//"b9cc10a9-916d-4481-b840-e6ad3ceaddf0"//"f9d8c5d0-c894-47a7-a7e8-3eb9541f0e07"//"6a46ff4d-9423-4a39-8d5a-db6b6c961439"//"456de863-cda2-495f-acab-495b4aece2cc"//"a8e9c835-09db-45dd-bbc1-8964baa337d6"//"e5616f6f-9a8b-460c-abaa-25b787841948"
    //module:["draw","prize","buy","device","media","social","widget","im","server","share","award"]
}, function(){
    //alert("欢迎使用阿里互动开放平台<br>"+navigator.userAgent);
    if(!(/iPhone|iPad|iPod/gi.test(navigator.userAgent)) && /TM\//gi.test(navigator.userAgent)){
        // Tida.praise = function(opt,callback){
            // TMM.APP.call("socialPlugin.praise",['{"accountId":"86428989","subType":"12121","opiFavourStatus":"true","targetType":"12121","opiFavourCount":"true","opiCommentCount":"false","targetId":"12121"}'],null,null,true);
        // };
        // Tida.follow = function(){
            // TMM.APP.call("socialPlugin.follow",["{'pubAccountId':'86428989'}"],null,null,true);
        // };
        // Tida.comment = function(){
            // TMM.APP.call("socialPlugin.comment",['{"subType":"12121","opiFavourStatus":"false","targetType":"12121","opiFavourCount":"false","opiCommentCount":"true","targetId":"12121"}'],null,null,true);
        // };
        // Tida.gateway = Tida.gateway = function(){
            // TMM.APP.call("Isv.gateway",['{"a":"b"}'],null,null, true);
        // };
    }
    
    // Tida.iServer({}, function(e){
//         
        // Tida.showDrawResult({
            // score : {
                // currPoint : "1234", // 若需要传单位："1234秒"
                // isBest : false
            // },
            // shareData : {
                // image : "http://img02.taobaocdn.com/tps/i2/T1gdi3Xb8pXXXXXXXX-230-35.png"
            // },
            // awards : [e]
        // }, function() {
//             
        // }); 
    // });
    /*
    var mtopParams = {
        eventName : 'mixNick',
        needLogin : false,
        businessParam : {
            bizType:"liebian1111.lottery",
            bizParam:JSON.stringify({
                appkey: "APP_TAOBAO_ELEVEN",//Tida.interactParams.appkey,
                "shopId": "2055970395", 
                "interactId": "251323d2-f262-4e10-b907-f8bab02afb22"  
                //"rnd": 5//Math.ceil(Math.random()*6)
            }),
            asac:"xxx"
        },
        mtopApi : "mtop.interact.wireless.draw",
        //mtopApi : "mtop.interact.aplatform.securySet",
        appkey : Tida.interactParams.appkey
    };
    Tida.mtopAsyc(mtopParams, function(e) {
        var data = {};
        if(lib.env.os.isIOS){
            data = e;
        }else{
            data = e.data;
        }
        alert(JSON.stringify(data));
        //callback && callback(data);
    });*/
    
    window.TMM && TMM.APP.call('GlobalNavigation.show', ["false"], function(e){
        alert("triggerAction suc:"+JSON.stringify(e))
    },function(e){
        alert("triggerAction fail:"+JSON.stringify(e))
    });
    
});
var n = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "isWin": "false",
            "nick": "z**o",
            "reason": ""
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "false",
        "shopNick": "店铺名",
        "isTmall": "true",
        "_log": ["liebian1111;{\"appkey\":\"APP_TAOBAO_ELEVEN\",\"shopId\":\"2055970395\",\"interactId\":\"c27335b4-c510-4183-a8e6-19ad57a1dc8a\"};"]
    }
};
var g = {
    "api": "mtop.taobao.aplatform.new.securyset",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardBean": {
                "awardId": "905003",
                "extValue1": "1",
                "extValue2": "2024713423",
                "extra": {
                    "flowSize": "1",
                    "sellerId": "2024713423"
                },
                "group": "1",
                "level": "1",
                "lotteryId": "1010003",
                "name": "流量包",
                "pointLimit": "0",
                "rate": "0",
                "remainig": "0",
                "total": "0",
                "type": "FLOW_PACKAGE"
            },
            "innerReason": "",
            "lotteryID": "1010003",
            "reason": "",
            "userBean": {
                "nick": "s**9",
                "userID": "3596961788"
            },
            "win": "true",
            "winningRecordID": "9028002",
            "winningTime": "1442212347398"
        },
        "valid": "true",
        "isTmall": "true",
        "_log": []
    }
}
var g1 = {
    "api": "mtop.taobao.aplatform.new.securyset",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType":1,
            value:1
        },
        "valid": "true",
        "isTmall": "false",
        "_log": [],
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
    }
}
var g2 = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "2",
            "style": "least3",
            "value": "5"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": ["liebian1111;{\"appkey\":\"APP_TAOBAO_ELEVEN\",\"shopId\":\"2055970395\",\"interactId\":\"b4bade0d-c43e-4053-9d87-0f800535a631\"};"]
    }
}
var g4 = {
    "api": "mtop.interact.aplatform.securyset",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "4",
            "value": "5",
            "couponType": "20151111"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": []
    }
}
var g5 = {
    "api": "mtop.interact.aplatform.securyset",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "5",
            uuid:"xxxx"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": []
    }
}
var g6 = {
    "api": "mtop.interact.aplatform.securyset",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "6",
            "uuid": "xxxx-xxx"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": []
    }
}

var g6x = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "6",
            "uuid": "xxxx-xxx"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": ["liebian1111;{\"appkey\":\"APP_TAOBAO_ELEVEN\",\"shopId\":\"2055970395\",\"interactId\":\"c27335b4-c510-4183-a8e6-19ad57a1dc8a\"};"]
    }
}

var f =  {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "nick": "t**2",
            "groupId": "1",
            "isWin": "true",
            "reason": "",
            "winningRecordId": "778457001",
            "winningTime": "2015-10-08 09:58:08",
            "awardId": "2560569",
            "awardType": "finalPrice",
            "awardName": "【天猫官方测试请不要拍不发货不退款后果自负】倩儿测试赠品2",
            "extValue1": "42756234974",
            "extValue2": "0.01",
            "extValue3": "263693041",
            "extValue4": "2.0",
            "extValue5": "{\"picUrl\":\"//img.alicdn.com/bao/uploaded/i4/TB1pEUzGXXXXXXBXpXXXXXXXXXX_!!0-item_pic.jpg\",\"itemUrl\":\"//detail.tmall.com/item.htm?id\\u003d42756234974\"}",
            "extra": {
                "oPrice": "2.0",
                "price": "0.01",
                "ext1": "2.0",
                "ext2": "{\"picUrl\":\"//img.alicdn.com/bao/uploaded/i4/TB1pEUzGXXXXXXBXpXXXXXXXXXX_!!0-item_pic.jpg\",\"itemUrl\":\"//detail.tmall.com/item.htm?id\\u003d42756234974\"}",
                "pic": "{\"picUrl\":\"//img.alicdn.com/bao/uploaded/i4/TB1pEUzGXXXXXXBXpXXXXXXXXXX_!!0-item_pic.jpg\",\"itemUrl\":\"//detail.tmall.com/item.htm?id\\u003d42756234974\"}",
                "itemId": "42756234974"
            }
        },
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
        "valid": "true",
        "shopNick": "B2C小店68",
        "isTmall": "true",
        "_log": ["liebian1111;tmall;"]
    }
}

var c = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "nick": "t**3",
            "groupId": 1,
            "isWin": true,
            "reason": "",
            "winningRecordId": 783409003,
            "winningTime": "2015-10-09 11:43:28",
            "awardId": 2540608,
            "awardType": "interactCoupon",
            "awardName": "互动到店联调优惠券",
            "extValue1": "263693041",
            "extValue2": "335752595",
            "extValue3": "3.01",
            "extValue4": "3.0",
            "extValue5": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}",
            "extra": {
                "ext1": "3.0",
                "ext2": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}",
                "sellerId": "263693041",
                "value": "3.0",
                "startFee": "3.01",
                "attribute": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}"
            }
        },
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
        "valid": true,
        "shopNick": "B2C小店68",
        "isTmall": true,
        "_log": ["liebian1111;tmall;"]
    }
};

var gg2 = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardType": "2",
            "style": "least3",
            "value": "10"
        },
        "logo": "/da/22/TB1SDGAXXXXXXcOXXXXSutbFXXX.JPG",
        "valid": "true",
        "shopNick": "店铺名",
        "isTmall": "false",
        "_log": []
    }
}


g =  {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "nick": "t**3",
            "groupId": 1,
            "isWin": true,
            "reason": "",
            "winningRecordId": 783409005,
            "winningTime": "2015-10-09 12:02:52",
            "awardId": 2560570,
            "awardType": "flowPackage",
            "awardName": "流量包",
            "extValue1": "1",
            "extValue2": "263693041",
            "extra": {
                "flowSize": "1",
                "sellerId": "263693041"
            }
        },
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
        "valid": true,
        "shopNick": "B2C小店68",
        "isTmall": true,
        "_log": ["liebian1111;tmall;"]
    }
}

var i = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "nick": "t**3",
            "groupId": 1,
            "isWin": true,
            "reason": "",
            "winningRecordId": 783409003,
            "winningTime": "2015-10-09 11:43:28",
            "awardId": 2540608,
            "awardType": "interactItemCoupon",
            "awardName": "互动到店联调优惠券",
            "extValue1": "263693041",
            "extValue2": "335752595",
            "extValue3": "3.01",
            "extValue4": "3.0",
            "extValue5": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}",
            "extra": {
                "ext1": "3.0",
                "ext2": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}",
                "sellerId": "263693041",
                "value": "3.0",
                "startFee": "3.01",
                "attribute": "{\"startDate\":\"2015-09-29 00:00:00\",\"shopName\":\"B2C小店68\",\"shopId\":\"58498830\",\"shopUrl\":\"//store.taobao.com/shop/view_shop.htm?shop_id\\u003d58498830\",\"endDate\":\"2015-11-30 23:59:59\"}"
            }
        },
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
        "valid": true,
        "shopNick": "B2C小店68",
        "isTmall": true,
        "_log": ["liebian1111;tmall;"]
    }
}

var h = {
    "api": "mtop.interact.wireless.draw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "result": {
            "awardId": 2540609,
            "awardName": "支付宝红包",
            "awardType": "alipayRedEnvelope",
            "extra": {
                "denomination": "0.1"
            },
            "groupId": 1,
            "isWin": true,
            "nick": "b**d",
            "reason": "",
            "winningRecordId": 783478103,
            "winningTime": 1444362224769
        },
        "logo": "/64/e1/TB1jbNVGXXXXXcgXXXXSutbFXXX.jpg",
        "valid": true,
        "shopNick": "店铺名",
        "isTmall": true,
        "_log": []
    }
}


var hb = {
    "api": "xxx.xxx.xxx.xx",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "win":"true",
        "value":"10"
    }
}

$("#testdraw").on("click", function(e){
    
    // Tida.isvdraw({
        // asac:"xxx"
    // },function(e){
        // alert(JSON.stringify(e))
    // })
    // return;
    
    //window.drawResultList = [Tida._parseOldDrawData(g.data.result)];
    window.drawResultList = [Tida._parseServerData(g5.data)];
    Tida.showDrawResult({
        score:{currPoint:2343},
        shareData : {
            image : "http://img02.taobaocdn.com/tps/i2/T1gdi3Xb8pXXXXXXXX-230-35.png"
        },
        awards : window.drawResultList || []
    }, function() {
        window.drawResultList=[];
    }); 
});

$("#category div[data-type]").on("click", function(){
    var type = $(this).attr("data-type");
    $(".page-content").scrollTo(0,$("#"+type).offset().top+$(".page-content").offset().top-50,300);
});
$(".refresh-link").on("click", function(e) {
    window.location.reload(true);
});
$("#addCalendar").on("click",function(){
    Tida.calendar.add({
         title: "日历测试", 
         startDate: "2015-07-09 14:20:00",
         endDate: "2015-07-09 14:40:00",
         location: "黄龙时代广场",
         link: "http://m.tmall.com",
         description: "day"
    }, function(result) {
        alert(JSON.stringify(result));
        if (result.errorCode) {
            // 添加日历失败
        } else {
            // 添加日历成功
        }
    });
});

window.alert = function(str) {
    myApp.alert(str, "接口回调JSON");
};
function hilightString( str ){
    // var str = "<pre><code>"+str+"</code></pre>";
    // Rainbow.color(function() {
        // $('#Rainbow').html(str);
    // });
    var div = document.createElement('div');
    div.innerHTML = '<pre><code data-language="javascript">'+str+'</code></pre>';
    document.getElementById('Rainbow').innerHTML = "";
    Rainbow.color(div, function() {
        document.getElementById('Rainbow').appendChild(div);
    });
}

$("#mixNick").on("click", function(){
    Tida.mixNick({},function(d){
        alert(JSON.stringify(d))
    })
});
$("#appinfo").on("click", function(e) {
    alert(JSON.stringify(Tida.appinfo));
});
$("#isSupportedApp").on("click", function(e) {
    alert(Tida.isSupportedApp);
});
$("#appinfo-demo").on("click", function(e) {
    hilightString('JSON.stringify(Tida.appinfo)');
});

// 登录
$("#login").on("click", function(e) {
    Tida.login(function(data){
        alert(JSON.stringify(data));
    });
});

$("#login-demo").on("click", function(e) {
hilightString('\n\
Tida.login(function(data){\n\
    alert(JSON.stringify(data));\n\
});')
});
// 授权
$("#doAuth").on("click", function(e) {
    Tida.doAuth({refresh: false},function(data){
        alert("suc"+JSON.stringify(data));
    });
});
// 授权
$("#forceDoAuth").on("click", function(e) {
    Tida.doAuth(true,function(data){
        alert(JSON.stringify(data));
    });
});
$("#forceDoAuth-demo").on("click", function(e) {
    hilightString('\n\
    Tida.doAuth(true,function(data){\n\
        alert(JSON.stringify(data));\n\
    }');
});

// 界面展示类
$("#toast").on("click", function(e) {
    Tida.toast("弱提示文案展示");
});
$("#setTitle").on("click", function(e) {
    var id = $(this).attr("change-num") || 0;
    id = parseInt(id, 10) + 1;
    $(this).attr("change-num", id);
    Tida.setTitle("标题改变" + id);
});
$("#showLoading").on("click", function(e) {
    Tida.showLoading("加载中...");
    setTimeout(function() {
        Tida.hideLoading();
    }, 3000);

});
$("#hideLoading").on("click", function(e) {
    Tida.hideLoading();
});
$("#showTitle").on("click", function(e) {
    Tida.showTitle();
});
$("#hideTitle").on("click", function(e) {
    Tida.hideTitle();
});
$("#pushWindow").on("click", function(e) {
    Tida.pushWindow("http://h5.m.taobao.com/app/uaward/index.html");
});
$("#popWindow").on("click", function(e) {
    Tida.popWindow();
});

$("#network").on("click", function(e) {
    Tida.network.getType(function(data) {
        alert(JSON.stringify(data));
    });
});
$("#network-demo").on("click", function(e) {
hilightString('\n\
Tida.network.getType(function(data) {\n\
    alert(JSON.stringify(data));\n\
})');
});
$("#geolocation").on("click", function() {
    Tida.geolocation.getCurrentPosition(function(data) {
        alert(JSON.stringify(data));
    });
});
$("#geolocation-demo").on("click", function() {
    hilightString('\n\
Tida.geolocation.getCurrentPosition(function(data) {\n\
    alert(JSON.stringify(data));\n\
});');
});
$("#photo").on("click", function() {
    
    /*
    document.addEventListener('WVPhoto.Event.takePhotoSuccess', function (e) {
    alert('event takePhotoSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('WVPhoto.Event.uploadPhotoSuccess', function (e) {
    alert('event uploadPhotoSuccess: ' + JSON.stringify(e.param));
});
document.addEventListener('WVPhoto.Event.uploadPhotoFailed', function (e) {
    alert('event uploadPhotoFailed: ' + JSON.stringify(e.param));
});
document.addEventListener('WVPhoto.Event.V2.progress', function (e) {
    alert('event V2.progress: ' + JSON.stringify(e.param));
});
var photoLocalPath; // 保存本地文件的路径。
var params = {
    // 得到照片后是否自动上传
    type: '1',
    // 是否只允许拍照或从相册选择
    mode: 'both',
    // 是否多图选择
    mutipleSelection: '1',
    // 最多选择张数
    maxSelect: 6,
    // 图片尺寸限制
    maxsize: {
         width: '300',
         height: '300'
    },
    // 业务代码
    bizCode: 'mtopupload',
    // 用户昵称
    usernick: 'anick'
};
window.WindVane.call('WVInteractsdkCamera', 'takePhotoInteract', params, function(e) {
    if (e && e.url) {
        photoLocalPath = e.localPath;
        document.getElementById('photoPreview').src = e.url;
    }
    alert('takePhoto success: ' + JSON.stringify(e));
}, function(e) {
    alert('takePhoto failure: ' + JSON.stringify(e));
});
    return;*/
    
    Tida.photo({
    }, function(data) {
        if(data.photo){
            //alert("成功");
            $("#api-result").html('<img src="'+data.photo+'" />');
            myApp.popup(".result-popup") ;
        }
        //alert(JSON.stringify(data))
    });
});
$("#photo-demo").on("click", function() {
    hilightString('\n\
Tida.photo({\n\
    \n\
}, function(data) {\n\
    if(data.photo){\n\
        alert("成功");\n\
    }\n\
});');
});
$("#visibility-watch").on("click", function(e) {
    if ($(this).attr("watch-id")) {
        alert("避免重复监听");
        return;
    }
    var watchId = Tida.pageVisibility.watch(function(data) {
        alert(JSON.stringify(data));
    });
    $(this).attr("watch-id", watchId);
});
$("#visibility-demo").on("click", function(e) {
hilightString('\n\
var watchId = Tida.pageVisibility.watch(function(data) {\n\
    if(data.visible == 1){\n\
        //页面显示了\n\
    }else{\n\
        //页面隐藏了\n\
    }\n\
});\n\
//取消监听\n\
Tida.pageVisibility.clearWatch(watchId)\n\
');
});
$("#visibility-clear").on("click", function(e) {
    Tida.pageVisibility.clearWatch(function(data) {
        alert(JSON.stringify(data));
    });
    $("#visibility-watch").removeAttr("watch-id");
});
$("#openClient").on("click", function(){
    Tida.openClient("http://coolgame.play.m.jaeapp.com/example/index.html");
});

$("#shake-watch").on("click", function(e) {
    if ($(this).attr("watch-id")) {
        alert("避免重复监听");
        return;
    }
    var watchId = Tida.shake.watch({
        sensitivity : 2,
        frequency : 150,
        callbackDelay : 2000
    }, function(data) {
        alert(JSON.stringify(data));
    });
    $(this).attr("watch-id", watchId);
});
$("#shake-demo").on("click", function(e) {
hilightString('\n\
var watchId = Tida.shake.watch({\n\
    sensitivity : 20,\n\
    frequency : 150,\n\
    callbackDelay : 2000\n\
}, function(data) {\n\
    alert(JSON.stringify(data));\n\
}\n\
// 取消监听 \n\
Tida.shake.clearWatch(watchId);\n\
');
});
$("#shake-clear").on("click", function(e) {
    Tida.shake.clearWatch($("#shake-watch").attr("watch-id"));
    $("#shake-watch").removeAttr("watch-id");
});
$("#orientation-watch").on("click", function(e) {
    var watchId = Tida.orientation.watch(function(data){
        $("#api-result").html(JSON.stringify(data));
    });
    $("#api-result").html("等待接收数据。。。");
    myApp.popup(".result-popup") ;
    $('.result-popup').on('close', function () {
      Tida.orientation.clearWatch(watchId);
    });
    //location.href = "orientation.html";
});
$("#orientation-demo").on("click", function(e) {
hilightString('\n\
var watchId = Tida.orientation.watch(function(data) {\n\
    alert(JSON.stringify(data));\n\
}\n\
// 取消监听 \n\
Tida.orientation.clearWatch(watchId);\n\
');    
});
$("#motion-watch").on("click", function(e) {
    var watchId = Tida.motion.watch({},function(data){
        $("#api-result").html(JSON.stringify(data));
    });
    $("#api-result").html("等待接收数据。。。");
    myApp.popup(".result-popup") ;
    $('.result-popup').on('close', function () {
      Tida.motion.clearWatch(watchId);
    });
    //location.href = "orientation.html";
});
$("#motion-demo").on("click", function(e) {
    
});
$("#blow-watch").on("click", function(e) {
    var watchId = Tida.blow.watch(function(data){
        $("#api-result").html(JSON.stringify(data));
    });
    $("#api-result").html("等待接收数据。。。");
    myApp.popup(".result-popup") ;
    $('.result-popup').on('close', function () {
      Tida.blow.clearWatch(watchId);
    });
    //location.href = "orientation.html";
});
$("#motion-demo").on("click", function(e) {
    
});

$("#audio-play").on("click", function(e) {
    var soundId = Tida.audio.play("http://g.alicdn.com/tmapp/firecrackers/1.0.1/resources/marronPlay.mp3", function(data) {
        alert(JSON.stringify(data));
    });
    $(this).attr("watch-id", soundId);
});
$("#audio-play-loop").on("click", function(e) {
    var soundId = Tida.audio.play({
        url:"http://g.alicdn.com/tmapp/firecrackers/1.0.1/resources/marronPlay.mp3",
        loop : true
    }, function(data) {
        alert(JSON.stringify(data));
    });
    $("#audio-play").attr("watch-id", soundId);
});
$("#audio-resume").on("click", function(e) {
    Tida.audio.resume($("#audio-play").attr("watch-id"));
});
$("#audio-pause").on("click", function(e) {
    Tida.audio.pause($("#audio-play").attr("watch-id"));
});
$("#audio-stop").on("click", function(e) {
    Tida.audio.stop($("#audio-play").attr("watch-id"));
    $("#audio-play").removeAttr("watch-id");
});
$("#scanCode").on("click", function(e) {
    Tida.scanCode(function(data){
        alert(JSON.stringify(data));
    });
});

// 交易相关
$("#detail").on("click", function() {
    // var a = {
                    // apiName : "Tida.trade",
                    // methodName : "detail",
                    // methodParam : {
                        // "itemId" : ""+44097189449
                    // },
                    // appKey : Tida.interactParams.appkey
                // };
                // window.WindVane.call("wopc", "invoke", a, function(){}, function(){});
    // return
    
    //return location.href = "http://detail.m.tmall.com/item.htm?id="+3501290788;
    Tida.detail({
        "itemId" : "3501290788"//"41991797317"
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#item-combo").on("click", function() {
    Tida.itemCombo({
        "itemId" : "26178352676",
        "comboId" : "244890000022711130"
    }, function(e) {
        alert(JSON.stringify(e));
    });
});

// 粉丝传播类
$("#praise").on("click", function() {
    Tida.praise({
        'pubAccountId' : '86428989',
        "targetId":"12121",
        'feedCover' : 'http://img.alicdn.com/tps/i1/TB1D7u3GVXXXXb5aXXXecUQ0VXX-1181-242.jpg',
        'feedTitle' : '测试',
        'feedUrl' : 'http://www.taobao.com',
        'targetType' : '100',
        'subType' : ''+23025092
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#follow").on("click", function() {
    Tida.follow({
        'pubAccountId' : "916201192"//'86428989',
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#itemFavor").on("click", function() {
    // WindVane.call('wopc', 'invoke', {
        // apiName : "Tida.server",
        // methodName : "getMtop",
        // isAsync : true,
        // eventName : "aaa",
        // methodParam : {
            // mtopApi : "com.taobao.mcl.fav.addcollect", // mtop.interact.current.mixusernick
            // mtopParam : {
                // ua : "",
                // version : "1.0",
                // needLogin : true,
                // isSec : 1,
                // businessParam : {"itemId":"26178352676","favType":"1"},
                // appKey : "23025092"
            // }
        // },
// 
        // appKey : "23025092"
    // }, function(e) {
        // alert("suc:"+JSON.stringify(e));
    // }, function(e) {
        // alert("fail:"+JSON.stringify(e));
    // });
    // return;
    // WindVane.call('wopc', 'mtop', {
        // v: '1.0',
        // post : '1',
        // ecode : '1',
        // api : "mtop.interact.current.mixusernick",
        // param : {"itemId":"26178352676","favType":"1",appKey : "23025092",appkey : "23025092"},
        // appKey : "23025092",
        // appkey : "23025092",
    // } , function(e) {
        // alert("suc:"+JSON.stringify(e));
    // }, function(e) {
        // alert("fail:"+JSON.stringify(e));
    // });
    // return;
    // Tida.mtopAsyc({
        // businessParam: { lotteryID: "Tida.interactParams.appkey"},
        // mtopApi: "mtop.interact.current.mixusernick",
        // appkey: Tida.interactParams.appkey
    // }, function(e) {
        // alert(JSON.stringify(e));
    // });
    // return;
    // var a = {
        // v: '2.0',
        // post : 'true',
        // ecode : 'true',
        // api : "com.taobao.mcl.fav.addcollect",
        // param : {"itemId":"26178352676","favType":"1",appKey : "23025092"},
        // appKey : Tida.interactParams.appkey
    // }
    // TMM.APP.call('Isv.mtopServer', [a], function(e) {
        // alert(JSON.stringify(e));
    // },function(e) {
        // alert(JSON.stringify(e));
    // });
    // return;
    Tida.itemFavor({
        'itemId' : "26178352676",//'86428989',
        "action":"add"
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#comment").on("click", function() {
    Tida.comment({
        'pubAccountId' : '86428989',
        //'feedCover' : 'http://gtms01.alicdn.com/tps/i1/TB1D7u3GVXXXXb5aXXXecUQ0VXX-1181-242.jpg',
        //'feedTitle' : '测试',
        //'feedUrl' : 'http://www.taobao.com',
        'targetId' : '12121',
        'targetType' : '100',
        'subType' : ''+23025092
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#share").on("click", function() {
    
    // return TMM.APP.call("Share.newShare",["扫码下载手机天猫，除了全天都能抢红包，还可以得到一个专属二维码，分享必有红包！", "http://gtms01.alicdn.com/tps/i1/T1VjkGFX0dXXaIIzZY-552-280.png"])
    // Tida.share({
        // image: "http://img02.taobaocdn.com/tps/i2/T1gdi3Xb8pXXXXXXXX-230-35.png",
        // shareType: 1,
        // text: "我在互动游戏，得了1234分，还挺好玩的，有本事超过我吧",
        // url: "http://m.laiwang.com/market/laiwang/tida-share-tb.php?interactId=e5616f6f-9a8b-460c-abaa-25b787841948&app=TM"
    // }, function(e) {
        // alert(JSON.stringify(e));
    // });
    Tida.share({
        url : "http://coolgame.play.m.jaeapp.com/doc/index.html",
        title : "分享标题",
        text : "分享内容",
        //image : "http://img01.taobaocdn.com/imgextra/i1/1928865133/TB22NwJdXXXXXaUXXXXXXXXXXXX_!!1928865133-0-tae.jpg_200x200",
        //image : "https://lovelove-play-m-jaeapp-com-jaecdn-com.alikunlun.com/res/icon_316.jpg",
        //image : "https://img.alicdn.com/tps/TB1vYGWJVXXXXc8XpXXXXXXXXXX-246-246.jpg",
        image : "https://flying-play-m-jaeapp-com-jaecdn-com.alikunlun.com/res/icon_246.jpg",
        weixinshare: 1,
        weixinAppId:"wx074a96f03ca16bbb",
        weixinMsgType: 'image'
    }, function(e) {
        alert(JSON.stringify(e));
    });
});
$("#gateway").on("click", function() {
   Tida.gateway({
       "a":"b"
   },function(e){
       alert(JSON.stringify(e));
   });
});
$("#draw").on("click", function() {
   $("#api-result").html("等待抽奖结果");
   myApp.popup(".result-popup") ;
       
   
   Tida.draw(function(e){
       if(window.drawResultList){
           drawResultList.push(e);
       }else{
           window.drawResultList = [e];
       }
       $("#api-result").html(JSON.stringify(e));
    });   
       
});
$("#showDrawResult").on("click", function() {
    Tida.showDrawResult({
        score : {
            currPoint : "12345分", // 若需要传单位："1234秒"
            isBest : false
        },
        shareData : {
            image : "http://img.taobaocdn.com/tps/i2/T1gdi3Xb8pXXXXXXXX-230-35.png"
        },
        awards : window.drawResultList || []
    }, function() {
        window.drawResultList=[];
    }); 
   
});
$("#queryScore").on("click", function() {
    Tida.queryScore(function(e) {
        alert(JSON.stringify(e));
    }); 
   
});
$("#showGameAward").on("click", function() {
    Tida.showGameAward(function(e) {
        alert(JSON.stringify(e));
    }); 
   
});
$("#saveScore").on("click", function() {
    Tida.saveScore({
        value: parseInt(Math.random()*1000)
    },function(e) {
        alert(JSON.stringify(e));
    }); 
   
});
// $("#wangwang").on("click", function() {
    // var options = {
         // sellerNick:"莱夫箱包旗舰店",
         // itemId :"42828909348",
         // shopId :"100179231",
         // orderId :""
     // };
// 
     // Tida.wangwang(options,function(data){
         // //alert("coin.add callback")
         // $("#api-result").html(JSON.stringify(data));
         // myApp.popup(".result-popup");
     // });
//    
// });
$("#cart").click(function () {
    Tida.cart({
        sellerNick : "白食王",//"mmaicco旗舰店",
        itemId : "43534992390",//"43853452175",
        skuId : "93475560669"//"80917501469"
    }, function (data) {
        $("#api-result").html(JSON.stringify(data));
        myApp.popup(".result-popup");
    });
});

var drawResult = {
    "api": "mtop.interact.isvlottery.idraw",
    "v": "1.0",
    "ret": ["SUCCESS::调用成功"],
    "data": {
        "succ": true,
        "data": {
            "nick": "t**2",
            "groupId": 1,
            "isWin": true,
            "reason": "",
            "winningRecordId": 335033123,
            "winningTime": "2015-2-12 00:51:54",
            "awardId": 1571167,
            "awardType": "interactCoupon",
            "awardName": "微淘奖池20元红包",
            "extValue1": "652154536",
            "extValue2": "221460712",
            "extValue3": "169",
            "extValue4": "20.0",
            "extValue5": "{\"startDate\":\"2015-02-06 00:00:00\",\"shopName\":\"自然堂然美专卖店\",\"shopId\":\"64135513\",\"shopUrl\":\"http://store.taobao.com/shop/view_shop.htm?shop_id\\u003d64135513\",\"endDate\":\"2015-05-03 23:59:59\"}",
            "extra": {
                "ext1": "20.0",
                "ext2": "{\"startDate\":\"2015-02-06 00:00:00\",\"shopName\":\"自然堂然美专卖店\",\"shopId\":\"64135513\",\"shopUrl\":\"http://store.taobao.com/shop/view_shop.htm?shop_id\\u003d64135513\",\"endDate\":\"2015-05-03 23:59:59\"}",
                "sellerId": "652154536",
                "value": "20.0",
                "attribute": "{\"startDate\":\"2015-02-06 00:00:00\",\"shopName\":\"自然堂然美专卖店\",\"shopId\":\"64135513\",\"shopUrl\":\"http://store.taobao.com/shop/view_shop.htm?shop_id\\u003d64135513\",\"endDate\":\"2015-05-03 23:59:59\"}",
                "startFee": "169"
            }
        }
    }
}

$("#wangwang").on("click", function() {
    var options = {
         sellerNick:"莱夫箱包旗舰店",
         itemId :"42828909348",
         shopId :"100179231",
         orderId :""
     };

     Tida.wangwang(options,function(data){
         //alert("coin.add callback")
         $("#api-result").html(JSON.stringify(data));
         myApp.popup(".result-popup");
     });
   
});
$("#prize").on("click", function() {
   var options = {
        firstRequest: true,
        secondRequest: false,
        prizeRanOut: false,
        firstRequestFail: false,
        benefitPrice: 0.10,
        prizeType: "ALIPAY_COUPON"
    };
    
    Tida.presentOpenBaoxiangDialog(options,function(data){
        alert(JSON.stringify(data));
    });
   
});

// $("#cart").click(function () {
    // Tida.cart({
        // sellerNick: "莱夫箱包旗舰店",
        // itemId: 42828909348, skuId: 73068526031
    // }, function (data) {
        // $("#api-result").html(JSON.stringify(data));
        // myApp.popup(".result-popup");
    // });
// });


